import { loadBMap } from '@/assets/js/map';
import { getDict } from '@/services/user';

const GlobalModel = {
  namespace: 'global',
  state: {
    dict: {
      currentUser: {},
    }, //字典
    IsLoadMap: false, //百度地图是否加载
  },
  effects: {
    *fetchBaiDuMap(_, { call, put }) {
      const res = yield loadBMap('WgxoQtwu8xRSoMQSHO6nzHC2Rdi8X9iy');
      yield put({
        type: 'UpdateLoadMap',
        payload: true,
      });
    },
    *fetchDict(_, { put, call }) {
      const response = yield call(getDict);
      // console.log(response.code == 200, response.data);
      if (response.code == 200) {
        yield put({
          type: 'saveDict',
          payload: response.data,
        });
      }
    },
  },
  reducers: {
    UpdateLoadMap(state, { payload }) {
      return { ...state, IsLoadMap: payload };
    },
    saveDict(state, { payload }) {
      return { ...state, dict: payload };
    },
  },
};

export default GlobalModel;
